<template>
  <div class="vertical-align-flex">
    <div class="field">{{item.label || item}}：</div>
    <div class="value">
      <div :class="['switch', {'switch-on': switchOn }] " @click="toggle"></div>
      <slot name="slot-switch" v-if="!this.$store.state.user.isMobile"></slot>
    </div>
    <div class="field-tip" v-if="this.$store.state.user.isMobile">
      <slot name="slot-switch"></slot>
    </div>
  </div>
</template>

<script>
  /**
   *  父级传递数据 v-model
   *  父级改写数据 @handleSwitch 事件对传递数据进行改写
   *  子组件只显示数据
   */
  export default {
    data(){
      return {
      }
    },
    computed: {
      switchOn(){
        if(this.value == '1' || this.value == true || this.value == 'ACCEPT') {
          return true
        } else {
          return false
        }
      }
    },
    props: {
      item:{

      },
      value: {
        type: [Boolean, String, Number,]
      }
    },
    methods: {
      toggle(){
        let data;
        if(this.value == '0' || this.value == '1'){
          data = this.value == '1' ? '0' : '1'
        } else if(this.value == 'ACCEPT' || this.value == 'REJECT'){
          data = this.value == 'ACCEPT' ? 'REJECT' : 'ACCEPT'
        } else if(this.value == 'enable' || this.value == 'disable'){
          data = this.value == 'enable' ? 'disable' : 'disable'
        } else if(this.value === "" || this.value == undefined ) {
          // boolean
          data = "1"
        } else {
          console.log("开关量未知情况")
        }
        this.$emit('input', data)
        this.$emit('handleSwitch')
      }
    },
    created(){

    }
  }
</script>

<style lang="scss" scoped>

</style>
